<?php

namespace app\adminapi\validate\game;

use app\common\validate\BaseValidate;
use app\common\model\game\Game;

/**
 * 游戏管理验证
 * Class GameValidate
 * @package app\adminapi\validate\game
 */
class GameValidate extends BaseValidate
{
    protected $rule = [
        'id' => 'require|checkGame',
        'name' => 'require|length:1,255',
        'eng_name' => 'require|length:1,255',

        //'is_show' => 'require|in:0,1',
    ];

    protected $message = [
        'id.require' => '游戏id不能为空',
        'name.require' => '游戏名称不能为空',
        'name.length' => '游戏名称长度须在1-255位字符',
        'eng_name.require' => '游戏英文名称不能为空',
        'eng_name.length' => '游戏英文名称长度须在1-255位字符',
    ];

    /**
     * @notes  添加场景
     * @return GameValidate
     * @date 2022/2/22 9:57
     */
    public function sceneAdd()
    {
        return $this->remove(['id'])
            ->remove('id','require|checkGame');
    }

    /**
     * @notes  详情场景
     * @return GameValidate
     * @date 2022/2/22 10:15
     */
    public function sceneDetail()
    {
        return $this->only(['id']);
    }

    /**
     * @notes  更改状态场景
     * @return GameValidate
     * @date 2022/2/22 10:18
     */
    public function sceneStatus()
    {
        return $this->only(['id', 'is_show']);
    }

    public function sceneEdit()
    {
    }

    /**
     * @notes  删除场景
     * @return GameValidate
     * @date 2022/2/22 10:17
     */
    public function sceneDelete()
    {
        return $this->only(['id']);
    }

    /**
     * @notes  检查指定游戏是否存在
     * @param $value
     * @return bool|string
     * @date 2022/2/22 10:11
     */
    public function checkGame($value)
    {
        $article = Game::findOrEmpty($value);
        if ($article->isEmpty()) {
            return '游戏不存在';
        }
        return true;
    }

}